Is it necessary to declare attribute [DataMember(Order=n)] on public method?

Posted by veera on Stack Overflow See other posts from Stack Overflow or by veera
Published on 2010-06-08T12:26:52Z Indexed on 2010/06/08 12:32 UTC
Read the original article Hit count: 220

Filed under:
|

In my solution, I have created public class to store value and already declare [DataContract/DataMember] attribute.

For example,

[DataContract] public class MeterSizeInfo { string _meterSizeId;

    [DataMember(Order = 1)]
    public string MeterSizeId
    {
        get { return this._meterSizeId; }
        set { this._meterSizeId = value; }
    }

    string _meterSizeName;

    [DataMember(Order = 2)]
    public string MeterSizeName
    {
        get { return this._meterSizeName; }
        set { this._meterSizeName = value; }
    }

}

Then I need to add another public method exposing to entire project. I wonder I have to add [DataMember(Order = 3)] for it or not.

    [DataMember(Order = 3)] //<--- must declare or not?
    public string DoSomething()
    {
        // do something...
    }

I understand that if I want to use serializer in protobuf-net to serialize my data stored in, I have to declare those attribute. but I'm not sure about that on method.

please help. Thank you in advance.

© Stack Overflow or respective owner

Related posts about protobuf-net

Related posts about datamember